//切换状态
$(".list_state").on("click", function() {
	$(".state_type").attr("data-id", $(this).attr("data-id"));
	$(".state_type").html($(this).html());
	p = 1;
	tiaozhuan(p);
})

//弹出框接口
function showAudit(obj, item) {
	$("#quaModal").modal();
	var a = $(obj).attr("data");
	console.log(a);
	$(".adv_zz").attr('data-id', item).html(a);
	//可用余额
	var id = $('.adv_zz').attr('data-id');

	$.ajax({
		url: url + "/sys/adAptitude/queryAdOwner",
		type: 'POST',
		//		参数需转为字符串
		data: id,
		//		json跨域
		dataType: 'json',
		//		contentType类型为json
		contentType: "application/json",

		//		请求头加上X-Token 
		 beforeSend: function(XMLHttpRequest) {
			//		token 为页面所获取
			   
			XMLHttpRequest.setRequestHeader("X-Token", token); 
		},
		useDefaultXhrHeader: false,
		success: function(result) {
			console.log(result);
			if(result.code == '0') {
				var data = result.data;
				$(".adv_zz").html(data.compay);
				$(".adv_zz1").html(data.adBrand);
				$(".adv_zz2").html(data.adComapyUrl);
				$(".adv_zz3").attr('src', data.businessUrl);
				$(".adv_zz4").attr('src', data.icpUrl);
				$(".adv_zz5").attr('src', data.taxCertificateUrl);
				$(".adv_zz6").attr('src', data.organizationQualificationUrl);
				$(".adv_zz7").attr('src', data.networkLicenseUrl);
				$(".adv_zz8").attr('src', data.legalPersonUrl);
				$(".adv_zz9").attr('src', data.medicalInstitutionUrl);
				$(".adv_zz10").attr('src', data.medicalAdvertisementUrl);
				$(".adv_zz11").attr('src', data.brandQualification);
				$(".chazhao_id").attr('data-id', data.id);
				if(data.status == "1") {
					$(".xxuy1").css('display', 'inline-block');
					$(".xxuy").css('display', 'inline-block');
				} else {
					$(".xxuy1").css('display', 'none');
					$(".xxuy").css('display', 'none');
				}
			} else {
				isErr(result);
			}
		},
		err: function(err) {
			layer.msg("请求失败");
		}
	});

}
//审核成功,失败
function audit(type) {
	var str = type == "1" ? "通过" : "拒绝";
	var ida = [Number($(".chazhao_id").attr('data-id'))];
	var k = {};
	k.ids = ida;
	k.state = type;
	$.ajax({
		url: url + "/sys/adAptitude/check",
		type: 'POST',
		//		参数需转为字符串
		data: JSON.stringify(k),
		//		json跨域
		dataType: 'json',
		contentType: "application/json",
		beforeSend: function(XMLHttpRequest) {
			XMLHttpRequest.setRequestHeader("X-Token", token); 
		},
		useDefaultXhrHeader: false,
		success: function(result) {
			console.log(result);
			if(result.code == '0') {
				layer.msg(result.msg, {
					time: 2 * 1000
				}, function() {
					p = 1;
					tiaozhuan(p);
					$("#quaModal").modal('hide');
				});
			} else {
				isErr(result);
			}
		},
		err: function(err) {
			layer.msg("请求失败");
		}
	});
}

//资质审核报表接口
var p = 1;
function tiaozhuan(p) {
	var pageSize = $('.ui-select-pagesize').val();
	var keyWord = $(".keyWord").val();
	var status = $(".state_type").attr("data-id");
	var d = {};
	d.pageSize = pageSize;
	d.keyWord = keyWord;
	d.page = p;
	d.status = status;
	$.ajax({
		url: url + "/sys/adAptitude/queryPage",
		type: 'POST',
		//		参数需转为字符串
		data: JSON.stringify(d),
		//		json跨域
		dataType: 'json',
		contentType: "application/json",
		beforeSend: function(XMLHttpRequest) {
			XMLHttpRequest.setRequestHeader("X-Token", token); 
		},
		useDefaultXhrHeader: false,
		success: function(result) {
			console.log(result);
			if(result.code == '0') {
				var data = result.data.rows;
				var html = "";
				for(var i in data) {
					html += '<tr  class="ng-scope"><td  class="ng-binding">' + data[i].userId + '</td><td  class="ng-binding">' + data[i].username + '</td>';
					html += '<td  class="ng-binding">' + data[i].adOwnerName + '</td>';
					html += '<td  class="ng-binding">' + data[i].parentName + '</td>';
					//审核状态
					if(data[i].status == "1") {
						html += '<td><p  class="text-success ng-scope">待审核</p></td>';
						html += '<td class="ng-scope"><a  onclick="showAudit(this,' + data[i].id + ')"  class="ng-scope">审核</a></td></tr>';
					} else if(data[i].status == "2") {
						html += '<td><p  class="text-success ng-scope">审核通过</p></td>';
						html += '<td class="ng-scope"><a  onclick="showAudit(this,' + data[i].id + ')"  class="ng-scope">查看</a></td></tr>';
					} else if(data[i].status == "3") {
						html += '<td><p  class="text-success ng-scope">审核拒绝</p></td>';
						html += '<td class="ng-scope"><a  onclick="showAudit(this,' + data[i].id + ')"  class="ng-scope">查看</a></td></tr>';
					} else {
						html += '<td><p  class="text-success ng-scope">未提交</p></td>';
						html += '<td class="ng-scope"><a  onclick="showAudit(this,' + data[i].id + ')"  class="ng-scope">未提交</a></td></tr>';
					}
				}
				$(".adv_list").html(html);
				var r = result.data.total;
				paging(p, pageSize, r);
			} else {
				isErr(result);
			}
		},
		err: function(err) {
			layer.msg("请求失败");
		}
	});
}
tiaozhuan(1);

//搜索按钮
$(".materialName_btn").on("click", function() {
	p = 1;
	tiaozhuan(p);
})